< previous page page_232 next page >

Page 232
program PlayFile can display only around 52. When the frames were stored on a relatively slow CD-ROM, PlayFile could display only 13 frames per second.
The following code shows how program PlayFile displays an animation sequence. The form-level variable FileName contains the base name for the files. For example, if the files are named Map_0.bmp, Map_l.bmp, and so on, then FileName is Map_.
e10a6a0a59f035e870d90cca05b85fce.gif
' Run the animation once or until Playing is False.
Private Sub PlayImagesOnce(ByVal ms_per_frame As Integer)
Dim i As Integer
Dim next_time As Long

    ' Get the current time.
    next_time = GetTickCount

    ' Start the animation.
    For i = 0 To NumImages - 1
        ' Display the next frame.
        picCanvas.Picture = _
            LoadPicture(FileName & Format$(i) & ".bmp")
        NumPlayed = NumPlayed + 1

        ' Wait till we should display the next frame.
        next_time = next_time + ms_per_frame
        WaitTill next_time

        If Not Playing Then Exit For
    Next i
End Sub
Storing Image Bits
Instead of storing bitmap images in controls or loading them from disk, you can load the images one at a time and use the GetBitmapBits API function to save the bitmaps' pixel values in an array. Then you can use the SetBitmapBits API function to display the images when you need them. GetBitmapBits and SetBitmapBits are described in Chapter 3, Advanced Color.
The following code shows how a program might use this technique. The LoadImages routine saves the bits for a series of images in the Bytes array. Subroutine PlayImages uses SetBitmapBits to display the images.
e10a6a0a59f035e870d90cca05b85fce.gif
Private NumImages As Integer
Private MaxImage As Integer

Private Bytes() As Byte 
Private BytesPerImage As Long
e10a6a0a59f035e870d90cca05b85fce.gif
' Load the images.

 
< previous page page_232 next page >